import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * ClassName: Java10_Object_Util
 * Package: PACKAGE_NAME
 * DESCRIPTION:工具类
 *
 * @Author 程翎钥
 * @Create 2024/4/11 23:14
 * @Version 1.0
 */
public class Java10_Object_Util {
    public static void main(String[] args) throws Exception {
        System.out.println(StringUtil.isEmpty(null));
        System.out.println(StringUtil.isEmpty("   "));
        System.out.println(StringUtil.isEmpty("abc"));
        System.out.println(StringUtil.isEmpty(""));
        System.out.println(StringUtil.makeString());
        System.out.println(StringUtil.makeString("abcdefg123456", 6));
        System.out.println(StringUtil.formatDate(new Date(), "yyyy-MM-dd"));
        System.out.println(StringUtil.parseDate("2024-04-12", "yyyy-MM-dd"));
    }
}
class StringUtil {
    //非空判断
    public static Boolean isEmpty(String str) {
        //如果字符串为null，为空
//        if (str == null) {
//            return true;
//        }
//
//        //如果字符串为空字符串，为空
//        if ("".equals(str)) {
//            return true;
//        }
//
//        //如果字符串都是空格，为空
//        if ("".equals(str.trim())) {
//            return  true;
//        }
//        return  false;
//    }
        if (str == null || "".equals(str.trim())) {
            return true;
        }
        return false;
    }

    public static Boolean isNotEmpty(String str) {
        return !isEmpty(str);
    }

    //生成随机字符串
    public static String makeString() {
        return UUID.randomUUID().toString();
    }

    public static String makeString(String from, int len) {
        if (len < 1) {
            return "";
        } else {
            char[] chars = from.toCharArray();
            StringBuilder str = new StringBuilder();
            for (int j = 0; j < len; j++) {
                Random random = new Random();
                int i = random.nextInt(chars.length);
                char c = chars[i];
                str.append(c);
            }
            return str.toString();
        }
    }

    //转换字符串
    public static String transform(String source, String encodeFrom, String encodeTo) throws Exception {
        byte[] bytes = source.getBytes(encodeFrom);
        return new String(bytes,encodeTo);
    }
    public static Date parseDate(String dateString,String format) throws Exception{
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.parse(dateString);
    }
    public static String formatDate(Date date, String format) throws Exception{
        SimpleDateFormat sdf = new SimpleDateFormat(format);
        return sdf.format(date);
    }
}

